
#ifndef COLORREPLACER_H
#define COLORREPLACER_H

#include <BMap>
#include <BColor>
#include <BImage>
#include <BPainter>
#include <BPointArray>
#include <BEventFilter>

#include "ImageLayer.h"

class ColorReplacer : public BEventFilter
{
public:
	ColorReplacer();
	~ColorReplacer();

	void setMatchColor(BColor color);
	void setMatchTolerance(int tolerance);
	void setTargetColor(BColor color);
	void setOnlyConstituency(bool constituency);

	void showMatchedGraph();
	void hideMatchedGraph();

	void replace();

protected:
	virtual void attached(BWidget* widget);
	virtual void detached(BWidget* widget);

	virtual void freshEvent(const BEvent& event);
	virtual void paintEvent(const BEvent& event);

	virtual void focusEvent(const BEvent& event);
	virtual void keyPressEvent(const BKeyEvent& keyEvent);
	virtual void keyReleaseEvent(const BKeyEvent& keyEvent);

	virtual void mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual void mouseLeaveEvent(const BMouseEvent& mouseEvent);
	virtual void mousePressEvent(const BMouseEvent& mouseEvent);
	virtual void mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);

private:
	BColor			_matchColor;
	int				_matchTolerance;
	BColor			_targetColor;
	bool			_onlyConstituency;
	bool			_dirtyPoints;
	BMap<ImageLayer*, BPointArray>	_layerPointsMap;
};

#endif
